package net.xdclass.controller;


import net.xdclass.controller.request.AccountLoginRequest;
import net.xdclass.controller.request.AccountRegistryRequest;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.service.AccountService;
import net.xdclass.service.FileService;
import net.xdclass.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2021-11-09
 */
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {
    
    @Autowired
    private FileService fileService;

    @Autowired
    private AccountService accountService;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("upload")
    public JsonData uploadUserImg(@RequestPart("file")MultipartFile file){
        String result = fileService.uploadUserImg(file);
        return result!=null ? JsonData.buildSuccess(result) : JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);
    }

    /**
     * 账号注册
     * @param request
     * @return
     */
    @PostMapping("registry")
    public JsonData register(@RequestBody AccountRegistryRequest request){
        JsonData jsonData = accountService.registry(request);
        return jsonData;
    }

    /**
     * 登录
     * @param request
     * @return
     */
    @PostMapping("login")
    public JsonData login(@RequestBody AccountLoginRequest request){
        return accountService.login(request);
    }


}

